package input;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

import util.PropertiesUtil;

public class DownloadFile {

	public void downloadFile(String url, String fileName) throws IOException {
		System.out.println("Downloading '"+"' from '"+url+"'.");
		Properties props = PropertiesUtil.loadProperties("loteria.properties");

		BufferedInputStream in = new java.io.BufferedInputStream(
				new java.net.URL(url).openStream());

		FileOutputStream fos = new java.io.FileOutputStream(new File(
				props.getProperty("download_folder"), fileName));

		BufferedOutputStream bout = new BufferedOutputStream(fos, 1024);

		byte[] data = new byte[1024];
		int x = 0;
		while ((x = in.read(data, 0, 1024)) >= 0) {
			bout.write(data, 0, x);
		}
		bout.close();
		in.close();
		
		System.out.println("Download complete.");
	}

}
